package org.example;

import java.util.Scanner;

public class Demo01 {
    public static void main(String[] args) {
        //控制台输入
        Scanner scanner = new Scanner(System.in);
        //创建对象
        Demo01 demo01 = new Demo01();

//        System.out.println(add3(scanner));
        m1(scanner);


//        System.out.println("请输入Java成绩：");
//        int a = scanner.nextInt();
//        System.out.println("请输入C成绩：");
//        int b = scanner.nextInt();
//        System.out.println("请输入D成绩：");
//        int c = scanner.nextInt();
//        int d = demo01.add(a,b,c);

//        System.out.println("总成绩为："+ d);
//        System.out.println("平均成绩为："+(d/3));

//        System.out.println("输入统计人数：");
//        int i = scanner.nextInt();
//        int[] dls = new int[i];
//        for (int j = 0; j < i; j++) {
//            System.out.println("请输入第"+(j+1)+"名学生成绩：");
//            //获取输入的数，存入数组
//            dls[j] = scanner.nextInt();
//        }
//        //调用方法
//        demo01.add2(dls);

    }
//    public int add(int a,int b,int c){
//        return a+b+c;
//    }
//    public int add2(int[] ds){ //传入可变参数，使用数组定义参数
//        int sum = 0;//总和
//        int svg = 0;//平均
//        for (int i = 0; i<ds.length; i++){
//            sum += ds[i];
//        }
//        svg = sum/ds.length;
//        System.out.println("总成绩为："+ sum);
//        System.out.println("平均成绩为："+svg);
//        return 0;
//    }

    public static Student add3(Scanner scanner){ //获取学生信息，并创建对象
        System.out.println("请输入学生姓名：");
        String name = scanner.next();
        System.out.println("请输入学生年龄：");
        int age = scanner.nextInt();
        System.out.println("请输入学生成绩：");
        double score = scanner.nextDouble();
        //创建学生对象
        return new Student(name, age, score);
    }

    public static void m1(Scanner scanner){
        System.out.println("请输入学生人数：");
        int count = scanner.nextInt();
        //创建学生数组
        Student[] students = new Student[count];
        for (int i = 0; i < count; i++) {
            Student student = add3(scanner);
            students[i] = student;
        }
        int sum = 0;//总和
        int avg = 0;//平均
        //计算成绩
        for (int i = 0; i < students.length; i++) {
            sum += students[i].getScore();
        }
        avg = sum/students.length;
        System.out.println("总成绩为："+ sum);
        System.out.println("平均成绩为："+avg);
    }
}
